package ThreadPool.test;

import java.lang.reflect.Field;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: 通过反射来修改自定义类型
 * @date 2022/12/15 21:17
 */
class User{
    private final int id = 1;

    private String name;

    @Override
    public String toString() {
        return "user{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}


public class ModifyingPrivateFinalFileds {

    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        User mod = new User();
        Field field = mod.getClass().getDeclaredField("name");
        field.setAccessible(true);
        field.set(mod,"oyz");
        Field id = mod.getClass().getDeclaredField("id");
        id.setAccessible(true);
        id.set(mod,2);
        System.out.println(mod);

    }

}
